The 'break' statement may be used within the compound statement representing the loop body, to cause immediate exit from the loop. It is usually used in conjunction with an 'if-else' statement to conditionally exit the loop. It should be used with care, since program clarity may be compromised when the control of the loop is no longer localized in the main loop condition expression. Consider the following example:
while (i < 10)
{
if (position[i] > 1000)
break;
printf("Position is: %d\n",position[i++]); /* note increment operator '++' */
}
Instead, it may be preferable to include the break condition into the main loop condition: